<?php

if (!defined('BASEPATH'))
    exit('No direct script access allowed');

class Contato_model extends CI_Model {

    function __construct() {
        parent::__construct();
        $this->load->config('parametros');
    }

    /**
     * Get user record by Id
     *
     * @param	int
     * @param	bool
     * @return	object
     */
    public function get($_id) {
        $this->db->where('id', trim($_id));
        $query = $this->db->get($this->config->item('dbCliente') . $this->config->item('tblContato'));
        if ($query->num_rows() > 0) {
            return $query->row();
        } else {
            return NULL;
        }
    }

    function getAllContatos() {
        $query = $this->db->get($this->config->item('dbCliente') . $this->config->item('tblContato'));
        if ($query->num_rows() > 0) {
            return $query->result();
        } else {
            return NULL;
        }
    }

    function atualizar($_id, $_array) {
        $this->db->where('id', $_id);
        $this->db->update($this->config->item('dbCliente') . $this->config->item('tblContato'), $_array);
        return TRUE;
    }

    function alterar_valor_campo($id_registro, $campo, $valor) {
        $this->db->where('id', $id_registro);
        $this->db->set($campo, $valor);
        $this->db->update($this->config->item('dbCliente') . $this->config->item('tblContato'));
        if ($this->db->affected_rows() > 0) {
            return TRUE;
        } else {
            return FALSE;
        }
    }

    function cadastrar($_array) {
        $this->db->insert($this->config->item('dbCliente') . $this->config->item('tblContato'), $_array);
        if ($this->db->affected_rows() > 0) {
            return TRUE;
        } else {
            return FALSE;
        }
    }
}